import punycode from 'punycode';

export default class Punycode {

  options = {
    smart: false,
  }

  static Encoder = class Encoder extends Punycode {
    static Name = "Punycode <%= UIText.encode %>";

    static Options = {
      smart: {type: 'switch', label: 'Only non-ASCII parts'},
    }

    compute(text) {
      if (this.options.smart) {
        return punycode.toASCII(text);
      } else {
        return punycode.encode(text);
      }
    }
  }

  static Decoder = class Decoder extends Punycode {
    static Name = "Punycode <%= UIText.decode %>";

    static Options = {
      smart: {type: 'switch', label: 'Only Punycoded parts'},
    }

    compute(text) {
      if (this.options.smart) {
        return punycode.toUnicode(text);
      } else {
        return punycode.decode(text);
      }
    }
  }
}
